﻿<phone:PhoneApplicationPage 
    x:Class="BF.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:BF="clr-namespace:BF"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="100*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="200*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="100*"/>
            <RowDefinition Height="100*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="BF for Windows Phone" Style="{StaticResource PhoneTextNormalStyle}"/>
        </StackPanel>

        
        <Canvas Grid.Row="1" HorizontalAlignment="Left">
            <Canvas.Resources>
                <Storyboard x:Name="tapeStoryboard">
                    <DoubleAnimation x:Name="tapeAnimation" Storyboard.TargetName="itTape" Storyboard.TargetProperty="(Canvas.Left)" Completed="tapeAnimation_Completed">
                    </DoubleAnimation>
                </Storyboard>
            </Canvas.Resources>
            <Polygon Fill="{StaticResource PhoneContrastForegroundBrush}" Canvas.ZIndex="10" >
                <Polygon.Points>
                    <Point X="225" Y="0" />
                    <Point X="240" Y="18" />
                    <Point X="255" Y="0" />
                </Polygon.Points>
            </Polygon>
            <ItemsControl Name="itTape" Canvas.Left="-96" ItemsSource="{Binding Mode=OneTime, BindsDirectlyToSource=True}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <!--<ItemsControl.Clip>
                    <RectangleGeometry Rect="96, 0, 480, 100">
                    </RectangleGeometry>
                </ItemsControl.Clip>-->
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <BF:TapeCell CellViewModel="{Binding}" ></BF:TapeCell>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Canvas>
        <TextBlock Margin="10,0,0,0" Grid.Row="2">Source code:</TextBlock>
        <ScrollViewer Name="svtxtCode" Grid.Row="3" VerticalScrollBarVisibility="Auto">
            <TextBox Name="txtCode" Text="{Binding Source, Mode=TwoWay, UpdateSourceTrigger=Explicit}" AcceptsReturn="True" TextWrapping="Wrap"></TextBox>
        </ScrollViewer>
        <ScrollViewer Name="svtbCode" Grid.Row="3" VerticalScrollBarVisibility="Auto" MaxHeight="200" Visibility="Collapsed">
            <TextBlock Name="tbCode" FontSize="28" TextWrapping="Wrap"></TextBlock>
        </ScrollViewer>
        <TextBlock Margin="10, 0, 0, 0" Grid.Row="4">Output:</TextBlock>
        <ScrollViewer Name="svtxtOutput" Grid.Row="5" VerticalScrollBarVisibility="Auto">
            <TextBox Name="txtOutput" Text="{Binding OutputText}" AcceptsReturn="True" TextWrapping="Wrap" IsReadOnly="True"></TextBox>
        </ScrollViewer>
        <Grid Grid.Row="6">
            <Grid.RowDefinitions>
                <RowDefinition Height="10">
                </RowDefinition>
                <RowDefinition Height="Auto">
                </RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100*">
                </ColumnDefinition>
                <ColumnDefinition Width="75*">
                </ColumnDefinition>
            </Grid.ColumnDefinitions>
            <TextBlock Margin="10, 0, 0, 0" VerticalAlignment="Bottom" Grid.Row="0">Input:</TextBlock>
            <TextBox Name="txtInput" Text="{Binding InputText, Mode=TwoWay}" Grid.Row="1" AcceptsReturn="True" TextWrapping="NoWrap"></TextBox>
            <toolkit:ListPicker ItemsSource="{Binding DelayOptions}" SelectedIndex="{Binding SelectedDelayIndex, Mode=TwoWay}" Grid.RowSpan="2" Grid.Column="2" Name="lpDelay" Header="Visualization delay:">
                <toolkit:ListPicker.FullModeItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" Style="{StaticResource menuItem}"></TextBlock>
                    </DataTemplate>
                </toolkit:ListPicker.FullModeItemTemplate>
            </toolkit:ListPicker>
        </Grid>
    </Grid>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/icons/appbar.transport.play.rest.png" Text="Run" Click="btnRun_Click" />
            <shell:ApplicationBarIconButton IconUri="/icons/appbar.save.rest.png" Text="Save" Click="btnSave_Click" />
            <shell:ApplicationBarIconButton IconUri="/icons/appbar.folder.rest.png" Text="Snippets" Click="btnLoad_Click" />
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="Help" Click="ApplicationBarHelp_Click"></shell:ApplicationBarMenuItem>
                <shell:ApplicationBarMenuItem Text="About" Click="ApplicationBarAbout_Click"></shell:ApplicationBarMenuItem>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>